<template>
	<view class="pages">
		<view class="pages-search">
			<view class="pages-search-input">
				<view class="pages-search-input--input">
					<up-search
						placeholder="请输入任务名称进行搜索" 
						v-model="params.taskName"
						shape="square"
						clearabled
						searchIcon="search"
						:showAction="false"
						bgColor="#F0F2FA"
					></up-search>
				</view>
				
				<view>
					<view class="pages-search-input--button">
						<text style="margin-right: 10rpx;">全部网格</text>
						<up-icon name="arrow-down"></up-icon>
					</view>
				</view>
			</view>
		</view>
		
		<view class="pages-total">
			<up-subsection
				:list="types" 
				:current="0"
				active-color="#2E90EC"
				bgColor="#fff"
				mode="subsection"
			></up-subsection>
		</view>
		
		
		<view class="pages-total">
			<view class="pages-total-font">
				共计<text style="color: #2E90EC;">{{ count }}</text>条任务
			</view>
		</view>
		
		<view class="pages-up-list">
			<up-list 
				@scrolltolower="scrolltolower"
				height="100%"
				width="100%"
			>
				<template v-if="params.pageNum === 1 && loading">
					<view class="pages-list-item" v-for="item of 4"  :key="item">
						<up-skeleton
							loading
							rows="3"
							title
							animate
						></up-skeleton>
					</view>
				</template>
				<template v-if="count === 0 && !loading">
					<up-empty icon="list" marginTop="300rpx"></up-empty>
				</template>
				
				<up-list-item 
					v-for="(item, index) of list" 
					:key="index"
				>
					<view class="pages-list-item" @click="onSkipRouterToDetail(item)">
						
						<view class="pages-item-title">
							<text>新桂花村6号楼</text>
							<text class="pages-item-title--tag" v-show="item.overdue == 1">逾期</text>
						</view>
						
						<view class="pages-item-row">
							<text class="pages-hint-title">处理人员</text>
							<view class="pages-hint-content pages-hint-content--active" @click.stop="onOpenCall">
								<up-icon
									name="phone" 
									color="#2979ff" 
									labelColor="#2979ff"
									size="32rpx"
									label="应急办"
									labelSize="28rpx"
								></up-icon>
							</view>
						</view>
						<view class="pages-item-row">
							<text class="pages-hint-title">所属网格</text>
							<text class="pages-hint-content">福保01</text>
						</view>
						<view class="pages-item-row">
							<text class="pages-hint-title">详细地址</text>
							<text class="pages-hint-content">
								<!-- <up-icon name="map" size="28" style="margin-right: 10rpx;"></up-icon> -->
								深圳市福田区菩提路82号深圳市福田区菩提路82号深圳市福田区菩提路82号深圳市福田区菩提路82号
							</text>
						</view>
						<view class="pages-item-row">
							<text class="pages-hint-title">处理时间</text>
							<text class="pages-hint-content">{{ item.startDate || '--' }} 至 {{ item.endDate || '--' }}</text>
						</view>
					</view>
				</up-list-item>
				
				<up-loadmore line loadingIcon="circle" v-show="count != 0" :status="loadmore" />
			</up-list> 
		</view>
		
		<up-modal 
			:show="showCallModal"
			closeOnClickOverlay
			@confirm="onCloseCall"
		>
			<view class="">
				<view class="pages-item-row">
					<text class="pages-hint-title" style="width: 300rpx;">曾文勇/应急办</text>
					<view class="pages-hint-content pages-hint-content--active" @click="onCallPerson">
						<up-icon
							name="phone" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="188****9090"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
				<view class="pages-item-row">
					<text class="pages-hint-title" style="width: 300rpx;">曾文勇/街道办</text>
					<view class="pages-hint-content pages-hint-content--active" @click="onCallPerson">
						<up-icon
							name="phone" 
							color="#2979ff" 
							labelColor="#2979ff"
							size="32rpx"
							label="188****9090"
							labelSize="28rpx"
						></up-icon>
					</view>
				</view>
			</view>
		</up-modal>
	</view>
</template>

<script setup>
import { onLoad, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { onHasUserinfoData, onSetUserinfoData, onGetUserinfoData, onGetRoleIdData,  onSetRoleIdData, onSetRolesData, onGetRolesData } from "/common/userinfo.js"
import { onGetTask } from "/serves/api.js";

const selectOrgRef = ref(null)


const loading = ref(false)
const loadmore = ref('loadmore')
const count = ref(0)
const list = ref([])
const params = ref({
	pageNum: 1,
	pageSize: 10,
	
	taskName: null,
	taskType: null,
	startDate: null,
	endDate: null,
	
	belongTo: 100,
})

const showCallModal = ref(false)

const onCallPerson = function ()  {
	uni.makePhoneCall({
		phoneNumber: '18664306776',
		success: () => onCloseCall(),
		fail: () => {}
	})
}

const onOpenCall  = function (e)  {
	e.stopPropagation()
	showCallModal.value = true
}

const onCloseCall = function ()  {
	showCallModal.value = false
}
 

// 跳转至详情页面
const onSkipRouterToDetail = (item) => {
	const { id } = item;
	const url = `/pages/site/index?id=${id}`
	uni.redirectTo({ url })
}


const onGetTaskList = async (refresh = false) => {
	loading.value = true
	loadmore.value = 'loading'
	try{
		const response = await onGetTask(params)
		const { rows, total } = response
		const temp = list.value
		rows.map(v => temp.push(v))
		count.value = total
		
		if (rows.length !== params.value.pageSize) loadmore.value = 'nomore'
		else loadmore.value = 'loadmore'
		
		if (refresh) {
			list.value = rows
			return
		}
		
		list.value = temp
	} finally {
		if (params.value.pageNum === 1) setTimeout(() => loading.value = false, 1800)
		else loading.value = false
	}
}

const tabs = reactive([
	{ name: '部门任务', value: 'dept' },
	{ name: '个人任务', value: 'user' },
]) 
const types = reactive([
	{ name: '已核查（888）', value: 'dept' },
	{ name: '待核查（666）', value: 'user' },
])

const scrolltolower  = function(e) {}

// 切换tabs
const onSkipTabs = function (e) {
	console.log(e)
}

const onSelectOrg = function () {
	selectOrgRef.value.onShowPopup()
}

const onGoBack = function () {
	uni.navigateBack()
}

onLoad(() => onGetTaskList())
</script>

<style scoped lang="scss">
.pages-search {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	background-color: #fff;
	box-sizing: border-box;
	padding: 30rpx;
}

.pages-search-input {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	
	&--input {
		width: calc(100% - 260rpx);
	}
	
	&--button {
		width: 230rpx;
		height: 34px;
		background: #F0F2FA;
		border-radius: 8rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #333333;
		display: flex;
		align-items: center;
		justify-content: center;
		
		&:active {
			opacity: 0.8;
			box-shadow: 0px 0px 10rpx 0px #6D728D;
		}
	}
}

.pages-total {
	width: 100%;
	padding: 20rpx 30rpx;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
	
	&-font {
		width: auto;
		font-size: 28rpx;
		color: #666;
		text-align: left;
	}
	
	&-button {
		width: 300rpx;
	}
}

.dropdown-item-content {
	width: 100%;
	box-sizing: border-box;
	background-color: #fff !important;
	padding: 0 30rpx;
	height: 400rpx;
}

.pages-up-list { 
	width: 100%;
	height: calc(100vh - 332rpx);
	box-sizing: border-box;
	padding: 0 30rpx;
	padding-bottom: env(safe-area-inset-bottom);
}

.pages-list-item {
	width: 100%;
	height: auto;
	background: #F6F9FF;
	box-shadow: 0px 0px 10rpx 0px  rgba(0,0,0,0.1);
	border-radius: 4rpx;
	box-sizing: border-box;
	padding: 24rpx 30rpx;
	margin-bottom: 30rpx;
	position: relative;
	overflow: hidden;
	transform: all 0.2s;
	
	&:active {
		background: #FAFCFF;
		box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.3);
	}
}

.pages-item-status {
	width: 150rpx;
	height: 150rpx;
	background-color: #317FFC;
	text-align: center;
	font-size: 24rpx;
	color: #FFFFFF;
	box-sizing: border-box;
	padding-top: 110rpx;
	transform: rotate(45deg);
	position: absolute;
	top: -75rpx;
	right: -75rpx;
	box-shadow: 4rpx 4rpx 4rpx 0px rgba(49, 127, 252, .3);
	
	&--warning {
		background-color: #FF9900;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(255, 153, 0, .3);
	}
	
	&--success {
		background-color: #00C500;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(0, 197, 0, .3);
	}
}

.pages-item-title {
	font-family: PingFangSC, PingFang SC;
	font-weight: 500;
	font-size: 36rpx;
	color: #171717;
	line-height: 1.5em;
	font-style: normal;
	width: 100%; 
	
	&--tag {
		padding: 5rpx 10rpx;
		font-size: 28rpx;
		color: #FF0000;
		border: 1px solid #FF0000;
		background-color: rgba(255, 0, 0, .1);
		margin-left: 20rpx;
		border-radius: 4rpx;
	}
}

.pages-item-row {
	width: 100%;
	min-height: 60rpx;
	height: auto;
	box-sizing: border-box;
	padding-top: 10rpx;
	display: flex;
	align-items: flex-start;
}

.pages-hint-title {
	width: 160rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-hint-content {
	display: inline-block;
	width: calc(100% - 160rpx);
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	transition: all .3s;
	
	&--active {
		padding-top: 5rpx;
		
		&:active {
			opacity: 0.9;
		}
	}
}

.pages-hint-content--flex {
	display: inline-flex;
	align-items: center;
}

.pages-hint-content--hint {
	margin-left: 10rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

</style>